json = require "cjson"

local P = ClassFromFile(...)

function P.IndexFun(t, k)
	local v = P.LoadConfig(k)
	rawset(t, k, v)
	return v
end

setmetatable(P, {__index = P.IndexFun})

function P.LoadConfig(configName)
	if self == nil then
		self = {}
	end
	
	local str = nil
	if Login.CanUseExternalResource() then
		str = ExternalResourceManager.GetString("json/"..configName)
	end

	if not str then
		local configAsset = ResourceManager.LoadAsset("json/"..configName, typeof(UnityEngine.TextAsset))
		if configAsset then
			str = configAsset.text
		end
	end
	return json.decode(str)
end

